﻿using AutoMapper;
using DFGK.IRepository;
using DFGK.IService;
using DFGK_WMS.Model.Dto.YS;
using DFGK_WMS.Model.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yitter.IdGenerator;

namespace DFGK.Service
{
    public class OtherTypeService : BaseService, IOtherTypeService
    {
        private readonly IOtherTypeRepository _otherTypeRepository;
        private readonly IUnitOfWork _unitOfWork;
        public OtherTypeService(IMapper mapper, IOtherTypeRepository otherTypeRepository, IUnitOfWork unitOfWork) : base(mapper)
        {
            _otherTypeRepository = otherTypeRepository;
            _unitOfWork = unitOfWork;
        }

        public bool AddOtherTypeList(List<OtherType> otherTypes, out string message)
        {
            message = string.Empty;
            foreach (var item in otherTypes)
            {
                item.Id = YitIdHelper.NextId();
                var employees = _otherTypeRepository.QueryIsEntityWhere(x => x.TypeCode == item.TypeCode);
                if (employees != null)
                {
                    message = $"{item.TypeCode}编码已存在";
                    return false;
                }

            }
            _otherTypeRepository.AddEntityList(otherTypes);
            return _unitOfWork.SaveChangesEntity();

        }
         public List<OtherType> ShowOtherType()
        {
            return _otherTypeRepository.GetAllEntityList();
        }

    }

}
